# Maintainer: Felix Yan <felixonmars@archlinux.org>

_hkgname=th-lift
pkgname=haskell-th-lift
pkgver=0.8.4
pkgrel=1
pkgdesc="Derive Template Haskell's Lift class for datatypes."
url="https://github.com/RyanGlScott/th-lift"
license=('BSD')
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'haskell-th-abstraction')
makedepends=('ghc')
source=(https://hackage.haskell.org/packages/archive/${_hkgname}/${pkgver}/${_hkgname}-${pkgver}.tar.gz)
sha512sums=('fe5d47cc5b9c4a6128761d044ad00262e316862888a218279b62b51b87f32398c534ca65407491d210e7d32bea53c77161333b98bcc969e077221f2d9e3c56f7')

build() {
    cd $_hkgname-$pkgver
    
    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname \
        --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm
    runhaskell Setup build $MAKEFLAGS
    runhaskell Setup register --gen-script
    runhaskell Setup unregister --gen-script
    sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
    sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

package() {
    cd $_hkgname-$pkgver
    
    install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
    install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
    runhaskell Setup copy --destdir="$pkgdir"
    install -D -m644 "BSD3" "${pkgdir}/usr/share/licenses/${pkgname}/BSD3"
    rm -f "${pkgdir}/usr/share/doc/${pkgname}/BSD3"
}
